package com.tanhua.app.Interceptor;

import com.tanhua.model.pojo.User;

/**
 * 线程变量工具类
 */
public class UserHolder {

    private static ThreadLocal<User> threadLocal = new ThreadLocal<>();

    // 将用户对象添加到线程变量中
    public static void set(User user) {
        threadLocal.set(user);
    }

    // 获取线程变量中的对象
    public static User get() {
        return threadLocal.get();
    }

    // 删除线程变量中的对象
    public static void remove() {
        threadLocal.remove();
    }

    // 获取线程变量中的id值
    public static Long getUserId() {
        if (threadLocal.get() == null) {
            return null;
        }
        return threadLocal.get().getId();
    }

    // 获取线程变量中的手机号
    public static String getUserMobile() {
        if (threadLocal.get() == null) {
            return null;
        }
        return threadLocal.get().getMobile();
    }

}
